﻿#region File Header

/* File Name    : FacebookEvent.cs
 * Description  : Specifies information about an event, including the location, event name
 * Log
 * Date             Author              Description
 * 15-Oct-2011      Robin Jome          Created the class
 * 17-Oct-2011      Robin Jome          Updated comments.
 *                                      Removed ToString() overload and added GetPostData() method
 */

#endregion

#region Namespaces

using System;
using System.Text;
using FacebookAPI.FacebookProperties;
using System.Runtime.Serialization;

#endregion

namespace FacebookAPI.Objects
{
    #region Class

    [DataContract]
    public class FacebookEvent : FacebookBaseObject
    {
        #region Properties

        [DataMember(Name = "description", EmitDefaultValue = true, IsRequired = false)]
        public string Description { get; set; }

        [DataMember(Name = "end_time", EmitDefaultValue = true, IsRequired = false)]
        public DateTime EndTime { get; set; }

        [DataMember(Name = "is_date_only", EmitDefaultValue = true, IsRequired = false)]
        public bool IsDateOnly { get; set; }

        [DataMember(Name = "owner", EmitDefaultValue = true, IsRequired = false)]
        public FacebookBaseObject Owner { get; set; }

        [DataMember(Name = "start_time", EmitDefaultValue = true, IsRequired = false)]
        public DateTime StartTime { get; set; }

        [DataMember(Name = "location", EmitDefaultValue = true, IsRequired = false)]
        public string Location { get; set; }

        [DataMember(Name = "privacy", EmitDefaultValue = true, IsRequired = false)]
        public string Privacy { get; set; }

        [DataMember(Name = "updated_time", EmitDefaultValue = true, IsRequired = false)]
        public DateTime UpdatedTime { get; set; }

        [DataMember(Name = "venue", EmitDefaultValue = true, IsRequired = false)]
        public FacebookBaseObject Venue { get; set; }

        [DataMember(Name = "ticket_uri", EmitDefaultValue = true, IsRequired = false)]
        public string TicketUri { get; set; }

        [DataMember(Name = "ticket_zone", EmitDefaultValue = true, IsRequired = false)]
        public string TimeZone { get; set; }

        #endregion

        #region Methods

        internal string GetPostData()
        {
            StringBuilder postData = new StringBuilder();
            postData.Append("name=").Append(Name);
            postData.Append("&privacy_type=").Append(Enum.GetName(typeof(FacebookPrivacyTypes), Privacy));
            if (StartTime != DateTime.MinValue)
                postData.Append("&start_time=").Append(StartTime);
            if (EndTime != DateTime.MinValue)
                postData.Append("&end_date=").Append(EndTime);
            postData.Append("&description=").Append(Description);
            if (!string.IsNullOrEmpty(Location))
                postData.Append("&location=").Append(Location);
            return postData.ToString();
        }

        #endregion
    }

    #endregion
}
